package BIO.test04;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 目标，实现伪异步通信架构
 * 思路：借助线程池
 */
public class Server {
    public static void main(String[] args) {
        System.out.println("=====服务端启动======");
        try {
            //1.定义serverSocket对象进行服务端的端口注册
            ServerSocket ss = new ServerSocket(9999);
            //2. 初始化线程池工具类
            HandlerSocketServerPool pool = new HandlerSocketServerPool(3,5,10);
            //3.定义一个死循环，不断接收客户端Socket
            while (true){
                Socket socket = ss.accept();
                //4.把socket对象包装为一个task对象交个线程池进行处理
                Runnable target = new ServerRunnableTarget(socket);
                pool.execute(target);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
